/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import entity.Pessoa;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.swing.JOptionPane;

/**
 *
 * @author Thiago
 */
public class DAO {

    EntityManagerFactory factory;
    EntityManager en;
    EntityTransaction transaction;
    DAO dao;

    public DAO() {
        factory = Persistence.createEntityManagerFactory("ProjetoJPAPU");
        en = factory.createEntityManager();
        transaction = en.getTransaction();
    }
 
    public boolean salva(Object obj) {
          try {
            transaction.begin();
            en.persist(obj);
            transaction.commit();

        } catch (Exception e) {
            transaction.rollback();
            JOptionPane.showMessageDialog(null, e.getMessage());
        }
        return false;
    }

    public boolean deletar(Object obj) {
        return false;
    }

    public boolean alterar(Object obj) {

        return false;

    }

    public List<Pessoa> listar() {

        return null;
    }

    public List<Pessoa> listar(String nome) {

        return null;
    }
}
